#ifndef WIDGET_H
#define WIDGET_H

#include <QWidget>
#include <QPushButton>
#include <QRadioButton>
#include <QButtonGroup>
#include <QCheckBox>
#include <QTextEdit>
#include <QTimer>
#include "code_syntaxhighlight.h"
#include "json_syntaxhighlight.h"
#include "device_syntaxhighlight.h"

class Widget : public QWidget
{
    Q_OBJECT

public:
    Widget(QWidget *parent = nullptr);
    ~Widget();

private:
    // 代码高亮
    QTextEdit* _codeEdit;
    QButtonGroup* _codeBtnGroup;
    QRadioButton* _openCodeBtn;
    QRadioButton* _keyboardCodeBtn;
    QPushButton* _codePreview;
    CodeSyntaxHighLight* _codeHighlighter;
    QTimer* _codeTimer;
    QString _codeString;
    int _codeIndex = 0;

    // Json高亮
    QTextEdit* _jsonEdit;
    QButtonGroup* _jsonBtnGroup;
    QRadioButton* _openJsonBtn;
    QRadioButton* _keyboardJsonBtn;
    QPushButton* _jsonPreview;
    JsonSyntaxHighlight* _jsonHighlighter;
    QTimer* _jsonTimer;
    QString _jsonString;
    int _jsonIndex = 0;

    // 下位机高亮
    QPushButton* _startRecvBtn;
    QPushButton* _clearDataBtn;
    DeviceSyntaxHighlight* _deviceHighlighter;
    QTextEdit* _deviceEdit;
    QTimer* _deviceTimer;

    void initLayout();
    void loadFile(QTextEdit* textEdit, const QString& fileName);

private slots:
    void onCodeRadioButtonClick();
    void onJsonRadioButtonClick();
    void onCodeTimerTimeout();
    void onJsonTimerTimeout();
    void onDeviceTimerTimeout();
};
#endif // WIDGET_H
